package com.code.coinprice.handlers.route.sub;

import com.code.coinprice.consts.CommonConstant;
import com.code.coinprice.handlers.route.CoinPriceInvokeHandler;
import com.code.coinprice.models.CoinPriceSource;
import com.code.coinprice.models.RelativeCoinPrice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Component(CommonConstant.XT + CommonConstant.COIN_PRICE_INVOKE_BEAN_NAME_SUFFIX)
public class XtCoinPriceInvokeApiHandler extends CoinPriceInvokeHandler {

    private static final Logger log = LoggerFactory.getLogger(XtCoinPriceInvokeApiHandler.class);

    @Resource
    private RestTemplate restTemplate;

    @Override
    public List<RelativeCoinPrice> getCoinPriceList(CoinPriceSource coinPriceSource) {
        List<RelativeCoinPrice> relativeCoinPriceList = new ArrayList<>();
        if (coinPriceSource != null) {
            // TODO 发送请求进行处理，待定
            String platformUrl = coinPriceSource.getPlatformUrl();
            // HttpEntity<String> formEntity = new HttpEntity<>(requestBody, getJsonHeader(requestBody));
            // HttpMethod method = HttpMethod.POST;
            // ResponseEntity<> response = restTemplate.exchange(url + "/coin_withdraw", method, formEntity, ClientResponse.class);
            RelativeCoinPrice relativeCoinPrice = new RelativeCoinPrice();
            relativeCoinPrice.setCoinName("BTC");
            relativeCoinPrice.setCoinPrice("30000.20");
            relativeCoinPriceList.add(relativeCoinPrice);
        }
        return relativeCoinPriceList;
    }

    @Override
    public String getCoinPrice(String source, String coinType) {
        // TODO 调用XT平台的根据币种类型单个获取币价的接口进行解析
        return CommonConstant.DEFAULT_COIN_PRICE;
    }

}
